package com.dh.blog.jsp.tags;

import java.io.File;
import java.io.Writer;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import com.ewei.web.common.utils.FileToolsBar;

/**
 * 自定义jsp标签
 * 引用磁盘下的文件
 * @author David
 *
 */
public class AbsoluteFileTag extends TagSupport {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 2573644078936312787L;
	private String path = null;
	private String dir = null;
	@Override
	public int doEndTag() throws JspException {
		super.release();
		return EVAL_PAGE;
	}

	@Override
	public int doStartTag() throws JspException {
		if(null!=dir&&!"".equals(dir)){
			File file = new File(dir);
			if(file.isDirectory()&&
				(null!=path&&!"".equals(path))){
				Writer writer = this.pageContext.getOut();
				FileToolsBar.readFileIntoHtml(new File(dir,path),writer);
			}
		}
		return SKIP_BODY;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getDir() {
		return dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}
	
}
